package com.scs.application.modules.upms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;
import com.scs.application.modules.upms.entity.GenDatasource;
import com.scs.application.modules.upms.request.GenDatasourceQueryRequest;
import com.scs.application.modules.upms.service.GenDatasourceService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 */
@RestController
@RequestMapping("/upms/gen_datasources")
public class GenDatasourceController extends CrudController<GenDatasource,String, GenDatasourceService> implements ImAndExAbleController<GenDatasourceQueryRequest> {


    @GetMapping("/page")
    public PageResult page(GenDatasourceQueryRequest request) {
        IPage page = service.page(request.getPage(), new QueryWrapper<GenDatasource>()
                .like(!StringUtils.isEmpty(request.getName()), "name", request.getName()));

        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(GenDatasourceQueryRequest request) {
        List<GenDatasource> list = service.list(new QueryWrapper<GenDatasource>()
                .like(!StringUtils.isEmpty(request.getName()), "name", request.getName()));
        return CommonResult.ok("查询成功", list);
    }

    @DeleteMapping("/clear_cache")
    public CommonResult clearCache(){
        service.clearCache();
        return CommonResult.ok("清除成功");

    }


}
